#!/usr/bin/perl -w
#
# $Id: ConnectionDialog.pm,v 1.8 2003/07/09 22:49:54 solovam Exp $
#
# This file is a part of gkismet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

#
# ConnectionDialog class
#
package ConnectionDialog;

use Gtk;
use Misc;
use strict;

#
# Constructor
#
sub new
{
	my $type = shift;
	my $self = {};
	bless $self, $type;

	my $gKismetApplication = shift;
	$self->{'gKismetApplication'} = $gKismetApplication;

	my $dialog = new Gnome::Dialog('Connect', 'Button_Ok', 'Button_Cancel');
	$self->{'dialog'} = $dialog;

	my $hostLabel = new Gtk::Label('Host:');
	my $portLabel = new Gtk::Label('Port:');

	my $hostEntry = new Gtk::Entry();
	$self->{'hostEntry'} = $hostEntry;
	my $portEntry = new Gtk::Entry();
	$portEntry->set_text('2501');
	$self->{'portEntry'} = $portEntry;

	my $hostHbox = new Gtk::HBox($false, 0);
	my $portHbox = new Gtk::HBox($false, 0);
	$hostHbox->pack_start($hostLabel, $false, $false, 15);
	$hostHbox->pack_end($hostEntry, $false, $false, 15);
	$portHbox->pack_start($portLabel, $false, $false, 15);
	$portHbox->pack_end($portEntry, $false, $false, 15);

	$dialog->vbox->pack_start($hostHbox, $false, $false, 10);
	$hostEntry->grab_focus();
	$dialog->vbox->pack_end($portHbox, $false, $false, 10);
	$dialog->set_parent($gKismetApplication->{'application'});
	$dialog->editable_enters($hostEntry);
	$dialog->set_default(0);
	$dialog->show_all();

	return $self;
}

#
# Run dialog
#
sub runAndClose
{
	my $self = shift;

	my $reply = $self->{'dialog'}->run_and_close();
	my $host = '';
	my $port = '';
	if($reply == 0)
	{
		$host = $self->{'hostEntry'}->get_text();
		$port = $self->{'portEntry'}->get_text();
		return($host, $port);
	}
	else
	{
		return undef;
	}
}

1;
